<?php 
include('../includes/db_connect.php'); 
$id = $_POST["id"];
$fName = $_POST["fName"];
$lName = $_POST["lName"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
//added 2008-08-08
$mInitial       								=$_POST["mInitial"];
$social_security_number  =$_POST["social_security_number"];
$medicaid_number       			=$_POST["medicaid_number"];
$medicare_number       			=$_POST["medicare_number"];
$county       										=$_POST["county"];

$query = "SELECT id FROM consumer WHERE id = ".$id;
if($row = mysql_fetch_array(mysql_query($query))) {
	$query = "UPDATE consumer 
								SET first_name = '".$fName."', 
										 last_name = '".$lName."', 
										 middle_initial = '".$mInitial."', 
										 ssn = '".$social_security_number."', 
										 medicaid = '".$medicaid_number."', 
										 medicare = '".$medicare_number."', 
										 address = '".$address."', 
										 city = '".$city."',
											county = '".$county."', 										 
										 state_id = ".$state.", 
										 zip = '".$zip."', 
										 phone = '".$phone."' 
								WHERE id=".$id;
	$status = "This file was updated successfully.";
} else {
	$query = "SELECT max(id)+1 AS id FROM consumer";
	$row = mysql_fetch_array(mysql_query($query));
	$id = $row["id"];
	$query = "INSERT INTO consumer 
								      (id, first_name, last_name, middle_initial, ssn, medicaid, medicare, address, city, county, state_id, zip, phone) 
								VALUES(".$id.",'".$fName."', '".$lName."', '".$mInitial."', '".$social_security_number."', '".$medicaid_number."', '".$medicare_number."', '".$address."', '".$city."', '".$county."',".$state.", '".$zip."', '".$phone."');";
	$status = "The new case file was successfully created.";
}
if(mysql_query($query)) {
  header("Location:../admin.php?action=cieedit&id=".$id."&Status=".$status);
  exit();
} else {
  header("Location:../admin.php?action=cieedit&id=".$id."&Error=Unable to update consumer due to system error.  Please contact system administrator.");
  //echo "Failure <br/>".$query;  
  exit();
}
?>